import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    count: 0,
    activedMenu: null,
    histories: []

  },
  mutations: {
    increment(state) {
      state.count++;
    },
    menuActived(state, menu) {
      state.activedMenu = menu;
    },
    addHistory(state, route) {

      var ind = state.histories.findIndex(function (his) {
        return his.name == route.name;
      });
      if (ind < 0) {
        //state.histories.splice(ind,1)
        //state.histories.splice(0,0,route)
        state.histories.push(route)
      }
    },
    removeHistory(state, route) {

      var ind = state.histories.findIndex(function (his) {
        return his.name == route.name;
      });
      if (ind >= 0) {
        state.histories.splice(ind,1)
        //state.histories.splice(0,0,route)

      }
    }
  },
  actions: {
    incrementAsync({commit}) {
      setTimeout(() => {
        commit('increment')
      }, 1000)

    }
  }
});

export default store;
